package com.shen.accountbook.greendao.manager;

import com.shen.accountbook.application.MyApp;
import com.shen.accountbook.config.Constant;
import com.shen.accountbook.greendao.DaoMaster;
import com.shen.accountbook.greendao.DaoSession;

/**
 *  greenDao管理类
 */
public class DaoManager {
    private static DaoManager mInstance;
    private DaoMaster mDaoMaster;
    private DaoSession mDaoSession;

    private DaoManager() {
        DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(MyApp.getInstance(),
                Constant.DB_NAME, null);
        // mDaoMaster = new DaoMaster(devOpenHelper.getWritableDatabase());
        mDaoMaster = new DaoMaster(devOpenHelper.getWritableDb());
        mDaoSession = mDaoMaster.newSession();
    }

    public DaoMaster getMaster() {
        return mDaoMaster;
    }

    public DaoSession getSession() {
        return mDaoSession;
    }

    public static DaoManager getInstance() {
        if (mInstance == null) {
            mInstance = new DaoManager();
        }
        return mInstance;
    }
}
